package com.tanhua.sso.controller;

import com.tanhua.sso.service.Smsservice;
import com.tanhua.sso.vo.ErrorResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("user")  //一级URL路径
public class SmsController {
    @Autowired
    private Smsservice smsservice;

    @PostMapping("login")
    public ResponseEntity<ErrorResult> sendCheckCode (@RequestBody Map<String,String> map){
        String phone = map.get("phone");
        ErrorResult result = null;
        try {
            result = smsservice.sendCheckCode(phone);
            if (result == null){  //ErrorResult是null的情况才是发送验证码成功
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            result.setErrCode("0000001");
            result.setErrMessage("xxxxxx");
        }
        return ResponseEntity.status(500).body(result);
    }
}
